<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>待办事项-修改状态</title>
  <style>
    ul{
      list-style-type: none;
      padding:0;
    }
    ul input, ul label {
      cursor: pointer;
    }
.done {
  text-decoration: line-through;
  color: #999;
}
  </style>
</head>
<body>
  
<div id="app">
  <div>
    <input type="text" v-model="todo" @keyup.enter="add">
    <button @click="add">添加新计划</button>
  </div>
  <ul>
    <li v-for="item in list" :key="item.id">
      <input type="checkbox" :id="'todo-'+item.id" :checked="item.done" @click="check($event, item)"> 
      <label :for="'todo-'+item.id" :class="{'done': item.done}">{{item.todo}}</label>
    </li>
  </ul>
</div>

<script src="vue.js"></script>
<script>
  var vm = new Vue({
    el: '#app',
    data:{
      todo: '',
      list: [
        { id: 1, todo: '去健身房健身', done: false },
        { id: 2, todo: '去饭店吃饭', done: true },
        { id: 3, todo: '去银行存钱', done: false },
        { id: 4, todo: '去商场购物', done: false }
      ]
    },
    methods: {
      add() {
        if (!this.todo) return;
        this.list.push({id: this.list.length+1, todo: this.todo, done: false});
        this.todo = '';
      },
      check(event, item) {
        item.done = event.target.checked
        console.log(item)
      },
    }
  })
</script>
</body>
</html>